package com.usian.behavior.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.apis.behavior.ApLikesBehaviorControllerApi;
import com.usian.behavior.service.ApLikesBehaviorService;
import com.usian.behavior.service.ApUnlikesBehaviorService;
import com.usian.model.behavior.dtos.FindlikeDto;
import com.usian.model.behavior.dtos.LikesBehaviorDto;
import com.usian.model.behavior.dtos.UnLikesBehaviorDto;
import com.usian.model.behavior.pojos.ApLikesBehavior;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/likes_behavior")
public class ApLikesBehaviorController implements ApLikesBehaviorControllerApi {
    @Autowired
    ApLikesBehaviorService apLikesBehaviorService;
    @Autowired
    ApUnlikesBehaviorService apUnlikesBehaviorService;
    /**
     * 袁浩 2022-6-29
     * 点赞行为保存
     * @param dto
     * @return
     */
    @PostMapping("/like")
    @Override
    public ResponseResult like(@RequestBody LikesBehaviorDto dto) {
        return apLikesBehaviorService.like(dto);
    }

    /**
     * 袁浩 2022-6-29
     * 点赞行为保存
     * @param dto
     * @return
     */
    @PostMapping("/unlike")
    @Override
    public ResponseResult unlike(@RequestBody UnLikesBehaviorDto dto) {
        return apUnlikesBehaviorService.unlike(dto);
    }

    /**
     * 查询出的点赞
     * @return
     */
    @PostMapping("/one")
    @Override
    public ApLikesBehavior findLikeByArticleIdAndEntryId(@RequestBody FindlikeDto dto) {
        ApLikesBehavior apLikesBehavior = apLikesBehaviorService.getOne(Wrappers.<ApLikesBehavior>lambdaQuery()
                .eq(ApLikesBehavior::getArticleId, dto.getArticleId()).eq(ApLikesBehavior::getEntryId, dto.getEntryId())
                .eq(ApLikesBehavior::getType, dto.getType()));
        return apLikesBehavior;
    }
}
